package com.example.service;

import com.example.entity.Books;
import com.example.entity.BooksCategory;
import com.example.mapper.BooksMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/*
书籍业务处理
 */
@Service
public class BooksService {

    @Resource
    private BooksMapper booksMapper;

    public void add(Books books) {
        booksMapper.insert(books);
    }

    public void deleteById(Integer id) {
        booksMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids){
            this.deleteById(id);
        }
    }

    public void updateById(Books books) {
        booksMapper.updateById(books);
    }

    public Books selectById(Integer id) {
        return booksMapper.selectById(id);
    }

    public List<Books> selectAll(Books books) {
        return booksMapper.selectAll(books);
    }

    public PageInfo<Books> selectPage(Books books, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Books> booksList = booksMapper.selectAll(books);
        return PageInfo.of(booksList);
    }
}
